package com.codebuffer.nowcoder;

public class StrToInt {

    public static int StrToInt(String str) {
        char[] chars = str.toCharArray();
        int f = 0;
        int i = 0;
        if(str.length()==0){
            return 0;
        }
        if(chars[0] == '+'){
            f = 1;
            i = 1;
        }else if(chars[0] == '-'){
            f = -1;
            i = 1;
        }
        int value = 0;
        for (; i < chars.length; i++) {
           if(chars[i]<='9' && chars[i]>='0'){
               if(f<0 && (Integer.MAX_VALUE/10<value)&&chars[i]>'8'){
                   return 0;
               }else if(Integer.MAX_VALUE/10<value&&chars[i]>'7'){
                   return 0;
               }
               value = value*10+(chars[i]-'0');
           }else {
               return 0;
           }
        }
        value = f * value;
        return value;
    }

    public static void main(String[] args) {

        System.out.println(StrToInt(""));
    }
}
